package com.geekchique.runningbuddy.activity;

import com.geekchique.runningbuddy.R;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.Menu.Item;
import android.widget.TextView;

import com.geekchique.runningbuddy.controller.DayControllerImpl;
import com.geekchique.runningbuddy.controller.IDayController;
import com.geekchique.runningbuddy.controller.IOptionsMenu;
import com.geekchique.runningbuddy.controller.OptionsMenuImpl;
import com.geekchique.runningbuddy.model.ListOfJogs;
import com.geekchique.runningbuddy.provider.ActivityID;
import com.geekchique.runningbuddy.view.JogListAdapter;

public class Day extends ListActivity{

	private IDayController dayOfJogDetailsController;
	private IOptionsMenu optionsMenu;

	@Override
	protected void onCreate(Bundle icicle) {
			super.onCreate(icicle);
			setContentView(R.layout.day);
			dayOfJogDetailsController = new DayControllerImpl(this);
			optionsMenu = new OptionsMenuImpl(this);

		  	Bundle bundle = this.getIntent().getExtras();
	        Integer dayOfMonth = bundle.getInt(ActivityID.DAY_OF_MONTH);
	        Integer monthOfYear = bundle.getInt(ActivityID.MONTH_OF_YEAR);
	        Integer year = bundle.getInt(ActivityID.YEAR);


	        TextView miles = new TextView(this);
	        miles.setText("miles Run");
			TextView name = new TextView(this);
			name.setText("name of jog");
			TextView timerun = new TextView(this);
			timerun.setText("time");

	        populateTodaysJoggingEntries(dayOfJogDetailsController.getDayOfJogs(dayOfMonth, monthOfYear, year));
	    }

	private void populateTodaysJoggingEntries(ListOfJogs jogEntries) {

		if (jogEntries.size() > 0){
			displayAllJogsTodayDetails(jogEntries);
		}

	}

	private void displayAllJogsTodayDetails(ListOfJogs jogEntries) {
		setListAdapter(new JogListAdapter(this, jogEntries, dayOfJogDetailsController));
	}

    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		optionsMenu.addAllActivitiesToMenu(menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(Item item) {
		optionsMenu.selectItem(item);
	    return super.onOptionsItemSelected(item);
	}
}
